package com.mnsq.im.business;

import com.mnsq.im.bean.SocketMessage;
import com.mnsq.im.bean.SocketsInfoHolder;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.util.StringUtils;

/**
 * @author zj00924
 */
public class ConnectEvent {
    static void accept(SocketMessage socketMessage, ChannelHandlerContext channel) {
        if (StringUtils.isEmpty(socketMessage.getToken())) {
            SocketsInfoHolder.sendMsg(channel, socketMessage.setContent("请登录后操作!"));
            channel.flush();
            channel.close();
            return;
        }
        SocketsInfoHolder.addChannel(socketMessage.getGroup(), channel);
        SocketsInfoHolder.sendMsg(channel, socketMessage.setContent("Welcome!"));
    }

    static void disAccept(SocketMessage socketMessage, ChannelHandlerContext channel) {
        SocketsInfoHolder.delChannel(socketMessage.getGroup(), channel);
    }
}
